/*
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-23 09:45:29
 * @LastEditTime: 2022-08-08 11:26:16
 */

import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
    {
      title: '认购调整单编号',
      field: 'adjustNo',
      minWidth: 170,
      header: {
        filter: {
          title: '认购调整单编号',
          key: 'adjustNo',
          placeholder: '请输入至少4位认购调整单编号',
          input: {},
          check: (val) => {
            if (val.adjustNo.length < 4) {
              _this.$Message.warning('请输入至少4位认购调整单编号。')
            }
            return !(val.adjustNo.length < 4)
          }
        },
      }
    },
    {
      title: '调整订单数',
      field: 'adjustCount',
      minWidth: 130,
    },
    {
      title: '调整前总面积(㎡)',
      field: 'beforeAdjustArea',
      minWidth: 150,
    },
    {
      title: '调整前认购总价(元)',
      field: 'beforeAdjustPrice',
      minWidth: 150,
    },
    {
      title: '调整后总面积(㎡)',
      field: 'afterAdjustArea',
      minWidth: 150,
    },
    {
      title: '调整后认购总价(元)',
      field: 'afterAdjustPrice',
      minWidth: 150,
    },
    {
      title: '调整面积差(㎡)',
      field: 'areaDV',
      minWidth: 130,
      slots: {
        default: (params, h) => {
          let color = params.row.areaDV > 0 ? '#D9001B' : params.row.areaDV < 0 ?
            '#70B603' : '#515a6e'

          return table.cell.text(h, {
            value: params.row.areaDV > 0 ? '+' + params.row.areaDV : params.row
              .areaDV,
            color: color
          })
        }
      }
    },
    {
      title: '调整总价差(元)',
      field: 'priceDV',
      minWidth: 130,
      slots: {
        default: (params, h) => {
          let color = params.row.priceDV > 0 ? '#D9001B' : params.row.priceDV < 0 ?
            '#70B603' : '#515a6e'

          return table.cell.text(h, {
            value: params.row.priceDV > 0 ? '+' + params.row.priceDV : params.row
              .priceDV,
            color: color
          })
        }
      }
    },
    {
      field: 'adjustmentReason',
      minWidth: 130,
      title: '调整原因',
    },
    {
      field: 'attachNum',
      minWidth: 130,
      title: '调整附件',
      slots: {
        default: (params, h) => {
          return table.cell.btn(_this, h, {
            title: params.row.attachNum,
            color: params.row.attachNum ? '#2d8cf0' : '#515a6e',
            event: params.row.attachNum ? 'preViewFile' : '',
            data: params.row
          })
        }
      }
    },
    {
      field: 'applyTime',
      minWidth: 180,
      title: '申请日期',
      header: {
        filter: dateOpt.range({
          title: '申请日期',
          startKey: 'applyStartDate',
          endKey: 'applyEndDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.applyStartDate, val
                .applyEndDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('申请日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.applyStartDate, val
              .applyEndDate).Y >= 2)
          }
        }),
      },
    },
    {
      title: '申请人',
      field: 'applyName',
      minWidth: 150,
    },
    {
      title: '状态',
      field: 'statusStr',
      minWidth: 120,
      header: {
        filter: {
          title: '状态',
          key: 'status',
          placeholder: '请选择状态',
          select: {
            multiple: true,
            options: dt.dictInfo().adjustmentStatus
          },
        },
      }
    },
    {
      field: 'auditTime',
      minWidth: 180,
      title: '审核日期',
      header: {
        filter: dateOpt.range({
          title: '审核日期',
          startKey: 'auditStartDate',
          endKey: 'auditEndDate',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.auditStartDate, val
                .auditEndDate).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('审核日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.auditStartDate, val
              .auditEndDate).Y >= 2)
          }
        }),
      },
    },
    {
      field: 'handles',
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: {
        default: (params, h) => {
          let cancleAdjustFlag = _this.unlocking('0104010403')
          let editFlag = _this.unlocking('0104010404')
          let delFlag = _this.unlocking('0104010405')

          let btns = []
          btns.push({
            title: '查看',
            event: 'detailFun',
            data: params.row
          })

          btns.push({
            title: (editFlag && (params.row.status ==
                'UNSUBSTITUTED' || params.row.status == 'NO_PASS')) ?
              '编辑' : '',
            event: 'editFun',
            data: params.row
          })

          btns.push({
            title: (params.row.status == 'APPROVAL' || params.row.status ==
              'PASS') ? '流程信息' : '',
            event: 'viewProcessFun',
            data: params.row
          })

          btns.push({
            title: cancleAdjustFlag && params.row.status ==
              'APPROVAL' ? '撤销调整' : '',
            event: 'cancleAdjustFun',
            data: params.row
          })

          btns.push({
            title: delFlag && params.row.status ==
              'UNSUBSTITUTED' ? '删除' : '',
            event: 'delAdjustFun',
            data: params.row
          })

          return table.cell.btns(_this, h, btns)
        }
      }
    }]
  }

}

export default Column